// 权限校验
import router from "./router"
import pinia from "./store"
import useUserStore from "./store/modules/user"
// 根据仓库寻找用户
let useStore = useUserStore(pinia)
// 路由的全局守卫
router.beforeEach((to,from,next)=>{
    const user = useStore.user;
    if(user && user._id){
        if(to.path==="/login"){
            next({path:"/"})
        }else{
            next()
        }
    }else{
        if(to.path==="/login"){
            next()
        }else{
            next({path:"/login"})

        }
    } 

})